from django.db import models
from django.contrib.auth.models import AbstractUser


# 


# 自定义用户模型
class User(AbstractUser):
    groups = models.ManyToManyField(
        'auth.Group',
        verbose_name='groups',
        blank=True,
        help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.',
        related_name='custom_user_groups',
        related_query_name='custom_user',
    )
    user_permissions = models.ManyToManyField(
        'auth.Permission',
        verbose_name='user permissions',
        blank=True,
        help_text='Specific permissions for this user.',
        related_name='custom_user_permissions',
        related_query_name='custom_user',
    )
    
    USER_TYPE_CHOICES = (
        ('regular', '普通用户'),
        ('cashier', '收银员'),
        ('admin', '管理员'),
    )
    MEMBERSHIP_CHOICES = (
        ('none', '无会员'),
        ('regular', '普通卡'),
        ('silver', '银卡'),
        ('gold', '金卡'),
    )

    email = models.EmailField(unique=True, null=True)
    phone = models.CharField(max_length=20, null=True)
    address = models.TextField(null=True)
    user_type = models.CharField(max_length=10, choices=USER_TYPE_CHOICES, default='regular')
    membership_type = models.CharField(max_length=10, choices=MEMBERSHIP_CHOICES, default='none')
    points = models.IntegerField(default=0)

    def __str__(self):
        return self.username